package com.ljd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljd.entity.EduComment;
import com.ljd.mapper.EduCommentMapper;
import com.ljd.service.EduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author ljd
 * @since 2022-01-04
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public Map<String, Object> getComments(Long current, Long pageSize, String courseId) {
        Page<EduComment> page = new Page<>(current, pageSize);
        LambdaQueryWrapper<EduComment> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EduComment::getCourseId,courseId)
                        .orderByDesc(EduComment::getGmtModified);
        baseMapper.selectPage(page,wrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("current",page.getCurrent());
        map.put("pageSize",page.getSize());
        map.put("total",page.getTotal());
        map.put("comments",page.getRecords());
        return map;
    }
}
